﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using SevenInvaders.common;

namespace SevenInvaders.LEVEL_DIEHL
{

    class DiehlPlayer:Player
    {
        animation stand;
        //animation walk;

        int tempoProximoTiro = 0;

        int intervaloEntreTiros = 500;

        bool podeAtirar = true;

        public DiehlPlayer(Texture2D texture, Vector2 position, int player, GameWindow qg,
            ContentManager Content) :
            base(texture, position, player, qg, Content)
        {
            this.Position = position;

            this.Velocity = new Vector2(10, 0);

            this.Window = qg;

            stand = new animation();
            stand.frame.X = 0;
            stand.frame.Y = 0;
            stand.frame.Width = 37;
            stand.frame.Height = 19;

            stand.frames = 1;
            stand.fps = 1;

            current_animation = stand;

            //walk = new animation();
            //walk.frame.X = 42 * 4;
            //walk.frame.Y = 0;
            //walk.frame.Width = 42;
            //walk.frame.Height = 54;

            //walk.frames = 15;
            //walk.fps = 7;

        }

        public void Update(GameTime gameTime, KeyboardState ks, KeyboardState ks_anterior)
        {
            #region Comandos
            if (ks.IsKeyDown(Keys.Right))
            {
                //current_animation = walk;
                this.Right = true;
                this.PositionX += 2;// this.Velocity.X;
            }
            else if (ks.IsKeyDown(Keys.Left))
            {
                //current_animation = walk;
                //this.Right = false;
                this.PositionX -= 2;// this.Velocity.X;
            }
            else
            {
                current_animation = stand;
            }

            if (ks.IsKeyDown(Keys.Up))
            {
                this.PositionY -= 2;
            }

            if (ks.IsKeyDown(Keys.Down))
            {
                this.PositionY += 2;
            }

            if (ks.IsKeyDown(Keys.X) && ! ks_anterior.IsKeyDown(Keys.X) && podeAtirar)
            {
                Shoot.list.Add(new Shoot(Game1.tiro, this.Position, Shoot.Direction.RIGHT, this.Velocity));
                podeAtirar = false;
                tempoProximoTiro = 0;
            }

            tempoProximoTiro += gameTime.ElapsedGameTime.Milliseconds;

            if (tempoProximoTiro > intervaloEntreTiros)
            {
                tempoProximoTiro = 0;
                podeAtirar = true;
            }

            #endregion

            #region Limite de tela
            if (this.PositionX + this.Texture.Bounds.Width > Window.ClientBounds.Width)
            {
                this.PositionX = Window.ClientBounds.Width - this.Texture.Bounds.Width;
            }

            if (this.PositionX <= 0)
            {
                this.PositionX = 0;
            }

            if (this.PositionY + this.Texture.Bounds.Height > Window.ClientBounds.Height)
            {
                this.PositionY = Window.ClientBounds.Height - this.Texture.Bounds.Height;
            }

            if (this.PositionY <= 0)
            {
                this.PositionY = 0;
            }
            #endregion

        }
    }
}
